﻿using BankUtil;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bank8583Helper
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("请输入原始报文！");
                return;
            }
            Iso8583Package package = new Iso8583Package("fullSchema.xml")
            {
                rec = strToToHexByte(textBox1.Text)
            };
            package.ParseBuffer(package.rec, true);
            textBox2.Text = package.GetLogText();
        }

        private static byte[] strToToHexByte(string hexString)
        {
            hexString = hexString.Replace(" ", "");
            if ((hexString.Length % 2) != 0)
                hexString += " ";
            byte[] returnBytes = new byte[hexString.Length / 2];
            try
            {
                for (int i = 0; i < returnBytes.Length; i++)
                    returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
            }
            catch (Exception ex)
            {

            }
            return returnBytes;
        }
        /// <summary>
        /// 签到交易模拟结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "600006000060010001020108000020000000c00012748276313031303438393631303530303030383036323532303000120000000100350003303031";
            this.button1_Click(sender, e);
        }
        /// <summary>
        /// 签到交易返回结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "60000000066001010102010810003800010AC00014748276132436112309650736086030333238343337343832373630303130313034383936313035303030303830363235323030001200000001003500408830D6A33153B9934C28E2B6C9F4AD62042B2638E73B74B5CBE255AA0000000000000000C7CB2868";
            this.button1_Click(sender, e);
        }
        /// <summary>
        /// 交易请求
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text = "60000600006001000102010200702406c020c09a111662232033050610020000000000000000017512722812051000000006346223203305061002d281222002000005043130313034383936313035303030303830363235323030313536CB0A175A7A29A693260000000000000000989F26080440D4362CBB2C5C9F2701809F100F07010103A0A000040A0100000000009F3704712119439F3602006B950500000060009A032011239C01009F02060000000000015F2A02015682027C009F1A0201569F03060000000000009F33030040000013220000010005104233363230303639";
            this.button1_Click(sender, e);
        }
        /// <summary>
        /// 交易返回结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text = "60000000066001000102010210703802800AD082031662232033050610020000000000000000017512721414331123000000303332383434363938373238353531303130343839363130353030303038303632353230301531343134343530302020203030303131353600989F26080440D4362CBB2C5C9F2701809F100F07010103A0A000040A0100000000009F3704712119439F3602006B950500000060009A032011239C01009F02060000000000015F2A02015682027C009F1A0201569F03060000000000009F330300400000004138344433363234";
            this.button1_Click(sender, e);
        }
    }
}
